<%@page import="qldc.pm.tienan.service.YeuCauTrichLucLocalServiceUtil"%>
<%@page import="qldc.pm.tienan.model.YeuCauTrichLuc"%>
<%@page import="qldc.pm.tienan.service.TienAnLocalServiceUtil"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.qtht.dmdc.service.TinhLocalServiceUtil"%>
<%@page import="qldc.pm.qtht.dmdc.model.Tinh"%>
<%@page import="java.util.List"%>
<%@page import="qldc.pm.tienan.service.DoiTuongTienAnLocalServiceUtil"%>
<%@page import="qldc.pm.tienan.searchcontainer.YeuCauTrichLucSearchTerms"%>
<%@page import="qldc.pm.tienan.searchcontainer.YeuCauTrichLucDisplayTerms"%>
<%@page import="qldc.pm.tienan.searchcontainer.YeuCauTrichLucSearch"%>
<%@page import="java.util.Date"%>
<%@page import="com.liferay.portal.kernel.util.StringPool"%>
<%@page import="java.text.SimpleDateFormat"%>

<%@include file="../../init.jsp"%>

<%
	PortletURL portletURL = renderResponse.createRenderURL();
	portletURL.setParameter("mvcPath", "/html/view.jsp");
	portletURL.setParameter("chonChucNangItem",		TienAnConstants.DS_BKTT);
	portletURL.setParameter("loaiBKTK",TienAnConstants.THONG_KE_TONG_QUAT);
	portletURL.setParameter("tabs1",TienAnConstants.THONG_KE_TONG_QUAT);

	PortletURL thoatUrl =  renderResponse.createRenderURL();
	thoatUrl.setParameter("mvcPath", "/html/view.jsp");
	thoatUrl.setParameter("chonChucNangItem",TienAnConstants.BAO_CAO_THONG_KE);
	String pathThemeImages = themeDisplay.getPathThemeImages();
	
%>

<portlet:resourceURL var="loadQuanHuyen" id="loadQuanHuyen">
	<portlet:param name="tinhIdSelected" value="{0}" />
</portlet:resourceURL>

<portlet:resourceURL var="loadPhuongXa" id="loadPhuongXa">
	<portlet:param name="quanHuyenIdSelected" value="{0}" />
</portlet:resourceURL>


<script type="text/javascript">
var NhapNgay = (function() {
	function NhapNgay() {}
	/*
	 * 
	 */
	 NhapNgay.prototype.initCalendars = function() {
			$("#<portlet:namespace/>tuNgayThongKe").datepicker({
				showOn: "both",
				buttonImage: "<%=pathThemeImages%>/common/calendar.png",
					buttonImageOnly : true,
					buttonText : "<liferay-ui:message key="tuNgayPhamToi" />",
					dateFormat : "dd/mm/yy",
					onClose: function( selectedDate ) {
						 $("#<portlet:namespace/>denNgayThongKe").datepicker( "option", "minDate", selectedDate );
						 }
				});
			$("#<portlet:namespace/>denNgayThongKe").datepicker({
				showOn: "both",
				buttonImage: "<%=pathThemeImages%>/common/calendar.png",
					buttonImageOnly : true,
					buttonText : "<liferay-ui:message key="denNgayPhamToi" />",
					dateFormat : "dd/mm/yy",
					onClose: function( selectedDate ) {
						 $("#<portlet:namespace/>tuNgayThongKe").datepicker( "option", "maxDate", selectedDate );
						 }
				});

		};

		return NhapNgay;
	})();

	$(function() {
		var dom = new NhapNgay();

		dom.initCalendars();
	});
</script>

<portlet:actionURL var="inThongKeURL">
	<portlet:param name="<%=TienAnConstants.ACTION_HANDLER_PARAM %>" value="<%=TienAnConstants.REPORT_ACTION %>"/>
	<portlet:param name="<%=Constants.ACTION %>" value="inReportThongKeYeuCauTrichLuc"/>
	<portlet:param name="redirect" value="<%=portletURL.toString() %>"/>
</portlet:actionURL>

<div  class="main-Content" >
	
	<form action="<%=inThongKeURL.toString() %>" id="<portlet:namespace />frm" method="POST" target="_blank">
			<%
			SimpleDateFormat sdf = new SimpleDateFormat(TienAnConstants.DATE_PATTERN);
			YeuCauTrichLucSearch YeuCauTrichLucSearch = new YeuCauTrichLucSearch(renderRequest,
					portletURL);
			YeuCauTrichLucDisplayTerms displayTerms = (YeuCauTrichLucDisplayTerms) YeuCauTrichLucSearch
					.getDisplayTerms();
			YeuCauTrichLucSearchTerms searchTerms = (YeuCauTrichLucSearchTerms) YeuCauTrichLucSearch
					.getSearchTerms();
			int sttDoiTuong = YeuCauTrichLucSearch.getDelta() * (YeuCauTrichLucSearch.getCur() - 1);
			long noiThuongTruTinhIdSelected = searchTerms.getTinhId();
			long noiThuongTruQuanHuyenIdSelected = searchTerms.getQuanHuyenId();
			long noiThuongTruPhuongXaIdSelected = searchTerms.getPhuongXaId();
			
		
		%>
		<table class="gridnormal"  style="padding-top: 10px;padding-left: 10px">			
			<tr>
				<td class="aui-w20"><liferay-ui:message key="vung-dia-ly" /></td>

				<td colspan="3" class="aui-w80" ><select class="display-inline" style="width: 30%" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.TINH_ID %>" id="<portlet:namespace/>noiThuongTruTinhId"
					onchange="loadQuanHuyen('<portlet:namespace />noiThuongTruTinhId', '<portlet:namespace />noiThuongTruQuanHuyenId', '<portlet:namespace />noiThuongTruPhuongXaId', '<%=loadQuanHuyen.toString()%>','<%=noiThuongTruQuanHuyenIdSelected%>');">
						<option value="0"><liferay-ui:message key="chon-tinh" /></option>
						<%
							List<Tinh> tinhs = TinhLocalServiceUtil.findAll();

							for (Tinh tinh : tinhs) {
						%>
						<option value="<%=tinh.getTinhId()%>" <%=(noiThuongTruTinhIdSelected == tinh.getTinhId() || tinh.getLaMacDinh()) ? "selected=selected"
						: StringPool.BLANK%>><%=tinh.getTenTinh()%></option>
						<%
							}
						%>
				</select>
				 <select class="display-inline" style="width: 30%" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.QUAN_HUYEN_ID %>" id="<portlet:namespace/>noiThuongTruQuanHuyenId" onchange="loadPhuongXa('<portlet:namespace/>noiThuongTruQuanHuyenId', '<portlet:namespace/>noiThuongTruPhuongXaId', '<%=loadPhuongXa.toString()%>', '<%=noiThuongTruPhuongXaIdSelected%>');">
				 	<option value="0"><liferay-ui:message key="chon-quan-huyen" /></option>
				 
				 </select>

					
				</td>
				
			</tr>
				<tr>
				<td class="txtlabel aui-w20"><liferay-ui:message key="co-quan-yeu-cau-trich-luc" /></td>
				<td class="aui-w30"><input type="text" id="<portlet:namespace/>coQuanYeuCauTrichLuc" value="<%=searchTerms.getCoQuanNguoiYeuCauTrichLuc() %>" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.CO_QUAN_NGUOI_YEU_CAU_TRICH_LUC %>" />
				
				</td>
				<td class="txtlabel aui-w20"><liferay-ui:message key="nguoi-thuc-hien-tao-trich-luc" /></td>
				<td class="aui-w30"><input type="text" id="<portlet:namespace/>nguoiThucHienTrichLuc" value="<%=searchTerms.getNguoiTaoTrichLuc()%>" name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.NGUOI_TAO_TRICH_LUC %>" />
				
				</td>
				
			</tr>
			
			<tr>
				<td class="txtlabel aui-w20"><liferay-ui:message key="ngay-tao-trich-luc-tu" /></td>
				<td colspan="3" class="aui-w80 ip-datepicker"  style="display: block; width: 100%"><input type="text"  style="display: inline-block;width: 105px" id="<portlet:namespace/>tuNgayThongKe" 
				name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.TU_NGAY_TAO_TRICH_LUC%>" 
				value="<%=Validator.isNotNull(displayTerms.getTuNgayTaoTrichLuc())?sdf.format(displayTerms.getTuNgayTaoTrichLuc()) : ""%>"/>
				&nbsp;&nbsp;<liferay-ui:message key="den-ngay" />
				&nbsp;&nbsp;<input  style="display: inline-block;width: 105px" type="text" id="<portlet:namespace/>denNgayThongKe" 
				name="<portlet:namespace/><%=YeuCauTrichLucDisplayTerms.DEN_NGAY_TAO_TRICH_LUC%>" 
				value="<%=Validator.isNotNull(displayTerms.getDenNgayTaoTrichLuc())?sdf.format(displayTerms.getDenNgayTaoTrichLuc()) : ""%>" />
				</td>
				
			</tr>
			
			<tr>
			<td></td>
			<td colspan="3">
			<div align="left">
					<input type=button onclick="timDanhSachHoGiaDinh();"  id="<portlet:namespace/>Tim"  class="btn btn-primary" name="<portlet:namespace/>Tim" value="<liferay-ui:message key="tim-kiem" />" /> 
			
				<input type=button onclick="taoBaoCaoDanhSachHoGiaDinh();" <%= noiThuongTruTinhIdSelected <= 0?"disabled='disabled'":"" %>  id="<portlet:namespace/>BaoCao"  class="btn btn-primary" name="<portlet:namespace/>BaoCao" value="<liferay-ui:message key="xuat-bao-cao" />" /> 
			 
				<input type=button class="btn"  name="<portlet:namespace/>thoat" value="<liferay-ui:message key="tro-ve" />"  onclick="window.location = '<%=thoatUrl.toString() %>';" />
			</div>
			</td>
			
			</tr>
		</table>
	</form>
<%
	if (searchTerms.getTinhId() > 0){
	%>
<liferay-ui:search-container  emptyResultsMessage="no-web-content-were-found"  searchContainer="<%=YeuCauTrichLucSearch %>">
	<liferay-ui:search-container-results>
		<%
		
			results =  YeuCauTrichLucLocalServiceUtil.thongKeYeuCauTrichLuc(searchTerms.getTinhId(), searchTerms.getQuanHuyenId(), searchTerms.getTuNgayTaoTrichLuc(), searchTerms.getDenNgayTaoTrichLuc(),searchTerms.getCoQuanNguoiYeuCauTrichLuc(),searchTerms.getHoVaTenNguoiYeuCauTrichLuc());

			total = results.size();
			
		
			pageContext.setAttribute("results", results);
			pageContext.setAttribute("total", total);
		%>
	</liferay-ui:search-container-results>
	
	<%
		int start = YeuCauTrichLucSearch.getDelta() * (YeuCauTrichLucSearch.getCur() - 1);
	%>
	
	<liferay-ui:search-container-row className="qldc.pm.tienan.dto.ThongKeTienAnDTO" keyProperty="index" modelVar="thongKe">

	
		<liferay-ui:search-container-column-text cssClass="txt-center aui-w3 " name="stt" value="<%=String.valueOf(++start) %>" />
		<liferay-ui:search-container-column-text cssClass="txt-center " name="khu-vuc" property="donViHanhChinh" />
		<liferay-ui:search-container-column-text  cssClass="txt-center aui-w10 " name="ho" property="hoKhau" />
		<liferay-ui:search-container-column-text cssClass="txt-center aui-w10" name="nhan-khau" property="nhanKhau" />
		<liferay-ui:search-container-column-text cssClass="txt-center aui-w10"  name="ho-co-tien-an" property="tongHoCoTienAn" />
		<liferay-ui:search-container-column-text cssClass="txt-center aui-w10"  name="tien-an" property="tienAn" />
		<liferay-ui:search-container-column-text cssClass="txt-center aui-w10"  name="trich-luc" property="trichLuc" />
		
		
	</liferay-ui:search-container-row>

	<liferay-ui:search-iterator searchContainer="<%=YeuCauTrichLucSearch %>" />
</liferay-ui:search-container>
<%

	} else {
		%>
		<h5><liferay-ui:message key="vui-long-chon-tieu-chi-lap-thong-ke" /></h5>
	<%}
%>
	</div>
<script type="text/javascript">
$(function() {
	 loadQuanHuyen('<portlet:namespace />noiThuongTruTinhId', '<portlet:namespace />noiThuongTruQuanHuyenId', '<portlet:namespace />noiThuongTruPhuongXaId', '<%=loadQuanHuyen.toString() %>','<%=noiThuongTruQuanHuyenIdSelected %>');
	 loadPhuongXa('<portlet:namespace/>noiThuongTruQuanHuyenId', '<portlet:namespace/>noiThuongTruPhuongXaId', '<%=loadPhuongXa.toString() %>', '<%=noiThuongTruPhuongXaIdSelected %>');
});

function timDanhSachHoGiaDinh(){
		$('#<portlet:namespace/>frm').removeAttr("target");
		$('#<portlet:namespace/>frm').removeAttr("action");
		$('#<portlet:namespace/>cmd').val('<%=TienAnConstants.TIM%>');
		$("#<portlet:namespace/>frm").attr('onsubmit', 'return true;');
		$("#<portlet:namespace/>frm").submit(); 
		
};
function taoBaoCaoDanhSachHoGiaDinh(){

		 $('#<portlet:namespace/>cmd').val('<%=TienAnConstants.IN%>');
			$("#<portlet:namespace/>frm").attr('target', '_blank');
			$("#<portlet:namespace/>frm").submit();
	 
	
};
</script>

